home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
NEW_TECH
/
MENTC.ZIP
/
WORD.C
< prev
Wrap
C/C++ Source or Header
|
1993-04-18
|
17KB
|
684 lines
/*
* The routines in this file implement commands that work word or a
* paragraph at a time. There are all sorts of word mode commands. If I
* do any sentence mode commands, they are likely to be put in this file.
*/
#include <stdio.h>
#include "estruct.h"
#include "eproto.h"
#include "edef.h"
#include "elang.h"
/* Word wrap on n-spaces. Back-over whatever precedes the point on the current
* line and stop on the first word-break or the beginning of the line. If we
* reach the beginning of the line, jump back to the end of the word and start
* a new line. Otherwise, break the line at the word-break, eat it, and jump
* back to the end of the word. Make sure we force the display back to the
* left edge of the current window
* Returns TRUE on success, FALSE on errors.
*/
PASCAL NEAR wrapword(f, n)
int f; /* default flag */
int n; /* numeric argument */
{
register int cnt; /* size of word wrapped to next line */
register int c; /* charector temporary */
/* backup from the <NL> 1 char */
if (!backchar(FALSE, 1))
return(FALSE);
/* back up until we aren't in a word,
make sure there is a break in the line */
cnt = 0;
while (((c = lgetc(curwp->w_dotp, curwp->w_doto)) != ' ')
&& (c != '\t')) {
cnt++;
if (!backchar(FALSE, 1))
return(FALSE);
/* if we make it to the beginning, start a new line */
if (curwp->w_doto == 0) {
gotoeol(FALSE, 0);
return(lnewline());
}
}
/* delete the forward white space */
if (!forwdel(0, 1))
return(FALSE);
/* put in a end of line */
if (!lnewline())
return(FALSE);
/* and past the first word */
while (cnt-- > 0) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
/* make sure the display is not horizontally scrolled */
if (curwp->w_fcol != 0) {
curwp->w_fcol = 0;
curwp->w_flag |= WFHARD | WFMOVE | WFMODE;
}
return(TRUE);
}
/*
* Move the cursor backward by "n" words. All of the details of motion are
* performed by the "backchar" and "forwchar" routines. Error if you try to
* move beyond the buffers.
*/
PASCAL NEAR backword(f, n)
int f,n; /* prefix flag and argument */
{
if (n < 0)
return(forwword(f, -n));
if (backchar(FALSE, 1) == FALSE)
return(FALSE);
while (n--) {
while (inword() == FALSE) {
if (backchar(FALSE, 1) == FALSE)
return(FALSE);
}
while (inword() != FALSE) {
if (backchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
return(forwchar(FALSE, 1));
}
/*
* Move the cursor forward by the specified number of words. All of the motion
* is done by "forwchar". Error if you try and move beyond the buffer's end.
*/
PASCAL NEAR forwword(f, n)
int f,n; /* prefix flag and argument */
{
if (n < 0)
return(backword(f, -n));
while (n--) {
/* scan through the current word */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
/* scan through the intervening white space */
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
return(TRUE);
}
/*
* Move forward to the end of the nth next word. Error if you move past
* the end of the buffer.
*/
PASCAL NEAR endword(f, n)
int f,n; /* prefix flag and argument */
{
if (n < 0)
return(backword(f, -n));
while (n--) {
/* scan through the intervening white space */
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
/* scan through the current word */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
return(TRUE);
}
/*
* Move the cursor forward by the specified number of words. As you move,
* convert any characters to upper case. Error if you try and move beyond the
* end of the buffer. Bound to "M-U".
*/
PASCAL NEAR upperword(f, n)
int f,n; /* prefix flag and argument */
{
int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (n < 0)
return(FALSE);
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (islowerz(c)) {
c = upperc(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
return(TRUE);
}
/*
* Move the cursor forward by the specified number of words. As you move
* convert characters to lower case. Error if you try and move over the end of
* the buffer. Bound to "M-L".
*/
PASCAL NEAR lowerword(f, n)
int f,n; /* prefix flag and argument */
{
int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (n < 0)
return(FALSE);
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (isupperz(c)) {
c = lowerc(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
return(TRUE);
}
/*
* Move the cursor forward by the specified number of words. As you move
* convert the first character of the word to upper case, and subsequent
* characters to lower case. Error if you try and move past the end of the
* buffer. Bound to "M-C".
*/
PASCAL NEAR capword(f, n)
int f,n; /* prefix flag and argument */
{
int c;
if (curbp->b_mode&MDVIEW) /* don't allow this command if */
return(rdonly()); /* we are in read only mode */
if (n < 0)
return(FALSE);
while (n--) {
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
if (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (islowerz(c)) {
c = upperc(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
while (inword() != FALSE) {
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (isupperz(c)) {
c = lowerc(c);
lputc(curwp->w_dotp, curwp->w_doto, c);
lchange(WFHARD);
}
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
}
}
}
return(TRUE);
}
/*
* Kill forward by "n" words. Remember the location of dot. Move forward by
* the right number of words. Put dot back where it was and issue the kill
* command for the right number of characters. With a zero argument, just
* kill one word and no whitespace. Bound to "M-D".
*/
PASCAL NEAR delfword(f, n)
int f,n; /* prefix flag and argument */
{
register LINE *dotp; /* original cursor line */
register int doto; /* and row */
register int c; /* temp char */
long size; /* # of chars to delete */
/* don't allow this command if we are in read only mode */
if (curbp->b_mode&MDVIEW)
return(rdonly());
/* ignore the command if there is a negative argument */
if (n < 0)
return(FALSE);
/* Clear the kill buffer if last command wasn't a kill */
if ((lastflag&CFKILL) == 0)
kdelete();
thisflag |= CFKILL; /* this command is a kill */
/* save the current cursor position */
dotp = curwp->w_dotp;
doto = curwp->w_doto;
/* figure out how many characters to give the axe */
size = 0;
/* get us into a word.... */
while (inword() == FALSE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
++size;
}
if (n == 0) {
/* skip one word, no whitespace! */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
++size;
}
} else {
/* skip n words.... */
while (n--) {
/* if we are at EOL; skip to the beginning of the next */
while (curwp->w_doto == llength(curwp->w_dotp)) {
if (forwchar(FALSE, 1) == FALSE)
return(FALSE);
++size;
}
/* move forward till we are at the end of the word */
while (inword() == TRUE) {
if (forwchar(FALSE, 1) == FALSE)
return(FAL